package pl.diagnoser.server.lpr;

import java.util.ArrayList;
import java.util.List;
import pl.diagnoser.client.dto.AttributeDictDTO;
import pl.diagnoser.client.dto.AttributeValuesDictDTO;
import pl.diagnoser.server.persistance.dao.AttributeDictDao;
import pl.diagnoser.server.persistance.dao.DefectDictDao;
import pl.diagnoser.server.persistance.dao.SymptomDictDao;
import lprlibrary.ml.Attribute;
import lprlibrary.ml.Attributes;

public class DiagnoserAttributes extends Attributes {
	
	public DiagnoserAttributes() {
        attributesList = new ArrayList<Attribute>();
        createGPAttributes();
	}

	private void createGPAttributes() {
        attributesList.add(createDiagnosisAttribute());
        attributesList.add(createSymptomAttribute());
        
        List<AttributeDictDTO> attributeDictDTO = new AttributeDictDao().getAttributeList(true);
        for(AttributeDictDTO attributeDict : attributeDictDTO) {
                Attribute tmpAttribute = new Attribute(attributeDict.getAttributeName().toLowerCase());
                for(AttributeValuesDictDTO attributeValues : attributeDict.getAttributeValues()) {
                        tmpAttribute.addValue(attributeValues.getAttributeValue().toLowerCase());
                }
                attributesList.add(tmpAttribute);
        }           
	}

	private Attribute createDiagnosisAttribute() {
        
        List<String> defectList = new DefectDictDao().getDefectsListAsString();
        Attribute diagnosisAttribute = new Attribute(DiagnoserKnowledgeBase.DEFECT_WITH);
        if(defectList != null)
                diagnosisAttribute.addValues(defectList);
        
        return diagnosisAttribute;
	}

	private Attribute createSymptomAttribute() {
        List<String> symptomList = new SymptomDictDao().getSymptomsListAsString();
        Attribute symptomAttribute = new Attribute(DiagnoserKnowledgeBase.SYMPTOM);
        
        if (symptomList != null)
        	symptomAttribute.addValues(symptomList);
        
        return symptomAttribute;
	}
}